<div class="layui-fluid">
  <div class="layui-card">

    <form class="layui-form layui-card-header layuiadmin-card-header-auto">
      <div class="layui-form-item">

        <div class="layui-inline">
          <label class="layui-form-label">用户名</label>
          <div class="layui-input-block">
            <input type="text" name="username" autocomplete="off" class="layui-input">
          </div>
        </div>
        
        <div class="layui-inline">
          <button class="layui-btn" lay-submit lay-filter="J_popup_form_search">搜索</button>
        </div>
      </div>
    </form>
    
    <div class="layui-card-body">
    	<div class="layui-row">
	      <form class="layui-form">
	        <div class="layui-form-item" style="margin-bottom: 5px;">
	          <div class="layui-inline">
	        	<label class="layui-form-label">添加到组</label>
	        	<div class="layui-input-inline">
			        <select class="layui-select" name="group">
			        {volist name="group" id="item"}
			        {if $item.type eq 'default'}
			        	<option value="{$item.id}">{$item.name}</option>
			        {/if}
			        {/volist}
			        </select>
	        	</div>
	          </div>
	          
	          <div class="layui-inline">
	        	<div class="layui-input-inline" style="height: 38px;">
			        <button class="layui-btn" lay-submit="" lay-filter="J_popup_ajaxSubmit">添加</button>
	        	</div>
	          </div>
	          
	        </div>
	      </form>
    	</div>
      <table id="J_popup_table_list" lay-filter="J_popup_table_list"></table>
    </div>
  </div>
</div>

<script>
layui.data.done = function(){
	layui.$('tr.layui-table-click')
};
;!function(){
  var $ = layui.$
  ,admin = layui.admin
  ,form = layui.form
  ,table = layui.table;

  form.render();

  //执行渲染
table.render({
  elem: '#J_popup_table_list'
  ,url: '{:url('ucentre/user/list')}'
  ,cols: [[
      {type: 'checkbox'}
      ,{field:'username',title:'用户名',minWidth:150}
      ,{field:'email',title:'邮箱',minWidth:200}
      ,{field:'mobile',title:'手机号',minWidth:170}
      ,{field:'create_time',title:'注册时间',minWidth:200}
  ]]
  ,page: true
    ,limit: 10
    ,height: 'auto'
  ,text: {
    none: '暂无数据！'
  }
});

    form.on('submit(J_popup_form_search)', function(obj){
    	obj.form.reset();
    	table.reload('J_popup_table_list', {
      		where: obj.field
    	});
    	return false;
    });
    
    form.on('submit(J_popup_ajaxSubmit)', function(obj){
		var data = table.checkStatus('J_popup_table_list'),post = [];
  	  	$.each(data.data,function(){
  	  		post.push(this.id);
        });
		if(post.length === 0){
			layer.msg('\u8bf7\u9009\u62e9\u6570\u636e');
			return false;
		}
        obj.field.id = post;

        admin.req({
           url: '{:url('wendasns/user/add')}'
           ,type: 'POST'
           ,dataType: 'json'
           ,data: obj.field
           ,done: function(res){
               layer.msg(res.msg, {time:1500}, function(){
    				admin.events.refresh();
    		   });
           }
           ,error: function(res){
    			layer.msg(res.msg);
    		}
        });
        return false;
    });
    
}();
</script>
